/**
Database Type: MySQL
当前生成的表 ${table.name}
@author: ${author}
@since: ${date}
@version ${version}
*/
<#assign menuId = mysqlStartMenuId>
<#assign metaId = mysqlStartMetaMenuId>
<#assign permissionId = mysqlStartPermissionId>
-- 默认绑定角色为admin管理员 id = 1
<#assign defaultBindRole = 1>
-- =================================================================BEGIN----菜单OR角色相关sql========================================================================
<#--菜单-->
<#--如果父id为0需要创建一个目录-->
<#if customPageConfig.pid == 0>
    -- 菜单dir
    INSERT INTO `sys_menu_resource` (`id`, `parent_id`, `name`, `menu_name`, `path`, `component`, `description`, `menu_type`, `level`, `permission`, `redirect`, `case_sensitive`, `meta_id`, `is_ext`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES (${menuId}, 0, '${package.ModuleName?cap_first}', '${moduleNameZh}', '/${package.ModuleName}', 'Layout', '', 'dir', NULL, '${package.ModuleName}:dir', '', b'0', ${metaId}, '0', '0', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}');
    INSERT INTO `sys_menu_meta` (`id`, `title`, `ignore_route`, `order_no`, `hide_menu`, `hide_tab`, `current_active_menu`, `hide_children_in_menu`, `carry_param`, `hide_breadcrumb`, `transition_name`, `frame_src`, `icon`, `affix`, `ignore_keep_alive`, `create_time`, `update_time`) VALUES (${metaId}, '${moduleNameZh}', b'0', 2, b'0', b'0', NULL, b'0', b'0', b'0', NULL, NULL, 'ion:settings-outline', b'0', b'0', '${.now?string("yyyy-MM-dd HH:mm:ss")}', '${.now?string("yyyy-MM-dd HH:mm:ss")}');
    <#assign pid = menuId>
    <#assign metaId = metaId + 1>
    <#assign menuId = menuId + 1>

    -- 菜单view
    INSERT INTO `sys_menu_resource` (`id`, `parent_id`, `name`, `menu_name`, `path`, `component`, `description`, `menu_type`, `level`, `permission`, `redirect`, `case_sensitive`, `meta_id`, `is_ext`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES (${menuId}, ${pid}, '${entity}', '${customTableInfo.businessName!table.comment!}', '${tsModelName}', '/${package.ModuleName}/${tsModelName}/index', '', 'menu', 1, '${package.ModuleName}:${tsModelName}:view', '', b'0', ${metaId}, '0', '0', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}');
    INSERT INTO `sys_menu_meta` (`id`, `title`, `ignore_route`, `order_no`, `hide_menu`, `hide_tab`, `current_active_menu`, `hide_children_in_menu`, `carry_param`, `hide_breadcrumb`, `transition_name`, `frame_src`, `icon`, `affix`, `ignore_keep_alive`, `create_time`, `update_time`) VALUES (${metaId}, '${customTableInfo.businessName!table.comment!}', b'0', 2, b'0', b'0', NULL, b'0', b'0', b'0', NULL, NULL, 'ion:settings-outline', b'0', b'0', '${.now?string("yyyy-MM-dd HH:mm:ss")}', '${.now?string("yyyy-MM-dd HH:mm:ss")}');

<#--绑定默认角色-->
    -- 角色綁定
    INSERT INTO `sys_role_menu_resource` (`role_id`, `menu_id`) VALUES ( ${defaultBindRole}, ${pid});
    INSERT INTO `sys_role_menu_resource` (`role_id`, `menu_id`) VALUES ( ${defaultBindRole}, ${menuId});
<#else>
    -- 菜单
    INSERT INTO `sys_menu_resource` (`id`, `parent_id`, `name`, `menu_name`, `path`, `component`, `description`, `menu_type`, `level`, `permission`, `redirect`, `case_sensitive`, `meta_id`, `is_ext`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES (${menuId}, ${customPageConfig.pid}, '${entity}', '${customTableInfo.businessName!table.comment!}', '${tsModelName}', '/${package.ModuleName}/${tsModelName}/index', '', 'menu', 1, '${package.ModuleName}:${tsModelName}:view', '', b'0', ${metaId}, '0', '0', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}');
    INSERT INTO `sys_menu_meta` (`id`, `title`, `ignore_route`, `order_no`, `hide_menu`, `hide_tab`, `current_active_menu`, `hide_children_in_menu`, `carry_param`, `hide_breadcrumb`, `transition_name`, `frame_src`, `icon`, `affix`, `ignore_keep_alive`, `create_time`, `update_time`) VALUES (${metaId}, '${customTableInfo.businessName!table.comment!}', b'0', 2, b'0', b'0', NULL, b'0', b'0', b'0', NULL, NULL, 'ion:settings-outline', b'0', b'0', '${.now?string("yyyy-MM-dd HH:mm:ss")}', '${.now?string("yyyy-MM-dd HH:mm:ss")}');


<#--绑定默认角色-->
    -- 角色綁定
    INSERT INTO `sys_role_menu_resource` (`role_id`, `menu_id`) VALUES ( ${defaultBindRole}, ${menuId});
</#if>
-- =================================================================END----菜单OR角色相关sql========================================================================

<#--按钮-->
<#--按钮的pid-->
-- =================================================================BEGIN----按钮相关sql========================================================================
<#assign btnPid = menuId>
<#assign metaId = metaId + 1>
<#assign menuId = menuId + 1>
<#if customPageConfig.showDelBtn>
    -- 删除按钮
    INSERT INTO `sys_menu_resource` (`id`, `parent_id`, `name`, `menu_name`, `path`, `component`, `description`, `menu_type`, `level`, `permission`, `redirect`, `case_sensitive`, `meta_id`, `is_ext`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES (${menuId}, ${btnPid}, '${entity}', '${customTableInfo.businessName!table.comment!}-删除按钮', '', '', '', 'button', 2, '${package.ModuleName}:${tsModelName}:del:btn', '', b'0', ${metaId}, '0', '0', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}');
    INSERT INTO `sys_menu_meta` (`id`, `title`, `ignore_route`, `order_no`, `hide_menu`, `hide_tab`, `current_active_menu`, `hide_children_in_menu`, `carry_param`, `hide_breadcrumb`, `transition_name`, `frame_src`, `icon`, `affix`, `ignore_keep_alive`, `create_time`, `update_time`) VALUES (${metaId}, '${customTableInfo.businessName!table.comment!}-删除按钮', b'0', 2, b'0', b'0', NULL, b'0', b'0', b'0', NULL, NULL, 'ion:settings-outline', b'0', b'0', '${.now?string("yyyy-MM-dd HH:mm:ss")}', '${.now?string("yyyy-MM-dd HH:mm:ss")}');

</#if>
<#assign metaId = metaId + 1>
<#assign menuId = menuId + 1>
<#if customPageConfig.showAddBtn>
    -- 新增按钮
    INSERT INTO `sys_menu_resource` (`id`, `parent_id`, `name`, `menu_name`, `path`, `component`, `description`, `menu_type`, `level`, `permission`, `redirect`, `case_sensitive`, `meta_id`, `is_ext`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES (${menuId}, ${btnPid}, '${entity}', '${customTableInfo.businessName!table.comment!}-新增按钮', '', '', '', 'button', 2, '${package.ModuleName}:${tsModelName}:add:btn', '', b'0', ${metaId}, '0', '0', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}');
    INSERT INTO `sys_menu_meta` (`id`, `title`, `ignore_route`, `order_no`, `hide_menu`, `hide_tab`, `current_active_menu`, `hide_children_in_menu`, `carry_param`, `hide_breadcrumb`, `transition_name`, `frame_src`, `icon`, `affix`, `ignore_keep_alive`, `create_time`, `update_time`) VALUES (${metaId}, '${customTableInfo.businessName!table.comment!}-新增按钮', b'0', 2, b'0', b'0', NULL, b'0', b'0', b'0', NULL, NULL, 'ion:settings-outline', b'0', b'0', '${.now?string("yyyy-MM-dd HH:mm:ss")}', '${.now?string("yyyy-MM-dd HH:mm:ss")}');

</#if>
<#assign metaId = metaId + 1>
<#assign menuId = menuId + 1>
<#if customPageConfig.showUpdateBtn>
    -- 编辑按钮
    INSERT INTO `sys_menu_resource` (`id`, `parent_id`, `name`, `menu_name`, `path`, `component`, `description`, `menu_type`, `level`, `permission`, `redirect`, `case_sensitive`, `meta_id`, `is_ext`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES (${menuId}, ${btnPid}, '${entity}', '${customTableInfo.businessName!table.comment!}-编辑按钮', '', '', '', 'button', 2, '${package.ModuleName}:${tsModelName}:edit:btn', '', b'0', ${metaId}, '0', '0', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}');
    INSERT INTO `sys_menu_meta` (`id`, `title`, `ignore_route`, `order_no`, `hide_menu`, `hide_tab`, `current_active_menu`, `hide_children_in_menu`, `carry_param`, `hide_breadcrumb`, `transition_name`, `frame_src`, `icon`, `affix`, `ignore_keep_alive`, `create_time`, `update_time`) VALUES (${metaId}, '${customTableInfo.businessName!table.comment!}-编辑按钮', b'0', 2, b'0', b'0', NULL, b'0', b'0', b'0', NULL, NULL, 'ion:settings-outline', b'0', b'0', '${.now?string("yyyy-MM-dd HH:mm:ss")}', '${.now?string("yyyy-MM-dd HH:mm:ss")}');
</#if>
<#assign metaId = metaId + 1>
<#assign menuId = menuId + 1>
<#if customPageConfig.existSearchField>
    -- 搜索按钮
    INSERT INTO `sys_menu_resource` (`id`, `parent_id`, `name`, `menu_name`, `path`, `component`, `description`, `menu_type`, `level`, `permission`, `redirect`, `case_sensitive`, `meta_id`, `is_ext`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES (${menuId}, ${btnPid}, '${entity}', '${customTableInfo.businessName!table.comment!}-搜索按钮', '', '', '', 'button', 2, '${package.ModuleName}:${tsModelName}:search:btn', '', b'0', ${metaId}, '0', '0', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}');
    INSERT INTO `sys_menu_meta` (`id`, `title`, `ignore_route`, `order_no`, `hide_menu`, `hide_tab`, `current_active_menu`, `hide_children_in_menu`, `carry_param`, `hide_breadcrumb`, `transition_name`, `frame_src`, `icon`, `affix`, `ignore_keep_alive`, `create_time`, `update_time`) VALUES (${metaId}, '${customTableInfo.businessName!table.comment!}-搜索按钮', b'0', 2, b'0', b'0', NULL, b'0', b'0', b'0', NULL, NULL, 'ion:settings-outline', b'0', b'0', '${.now?string("yyyy-MM-dd HH:mm:ss")}', '${.now?string("yyyy-MM-dd HH:mm:ss")}');
</#if>
<#assign metaId = metaId + 1>
<#assign menuId = menuId + 1>
<#if customPageConfig.showExportBtn>
    -- 导出按钮
    INSERT INTO `sys_menu_resource` (`id`, `parent_id`, `name`, `menu_name`, `path`, `component`, `description`, `menu_type`, `level`, `permission`, `redirect`, `case_sensitive`, `meta_id`, `is_ext`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES (${menuId}, ${btnPid}, '${entity}', '${customTableInfo.businessName!table.comment!}-导出按钮', '', '', '', 'button', 2, '${package.ModuleName}:${tsModelName}:export:btn', '', b'0', ${metaId}, '0', '0', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}');
    INSERT INTO `sys_menu_meta` (`id`, `title`, `ignore_route`, `order_no`, `hide_menu`, `hide_tab`, `current_active_menu`, `hide_children_in_menu`, `carry_param`, `hide_breadcrumb`, `transition_name`, `frame_src`, `icon`, `affix`, `ignore_keep_alive`, `create_time`, `update_time`) VALUES (${metaId}, '${customTableInfo.businessName!table.comment!}-导出按钮', b'0', 2, b'0', b'0', NULL, b'0', b'0', b'0', NULL, NULL, 'ion:settings-outline', b'0', b'0', '${.now?string("yyyy-MM-dd HH:mm:ss")}', '${.now?string("yyyy-MM-dd HH:mm:ss")}');


</#if>
<#assign metaId = metaId + 1>
<#assign menuId = menuId + 1>
<#if customPageConfig.showImportBtn>
    -- 导入按钮
    INSERT INTO `sys_menu_resource` (`id`, `parent_id`, `name`, `menu_name`, `path`, `component`, `description`, `menu_type`, `level`, `permission`, `redirect`, `case_sensitive`, `meta_id`, `is_ext`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES (${menuId}, ${btnPid}, '${entity}', '${customTableInfo.businessName!table.comment!}-导入按钮', '', '', '', 'button', 2, '${package.ModuleName}:${tsModelName}:import:btn', '', b'0', ${metaId}, '0', '0', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}');
    INSERT INTO `sys_menu_meta` (`id`, `title`, `ignore_route`, `order_no`, `hide_menu`, `hide_tab`, `current_active_menu`, `hide_children_in_menu`, `carry_param`, `hide_breadcrumb`, `transition_name`, `frame_src`, `icon`, `affix`, `ignore_keep_alive`, `create_time`, `update_time`) VALUES (${metaId}, '${customTableInfo.businessName!table.comment!}-导入按钮', b'0', 2, b'0', b'0', NULL, b'0', b'0', b'0', NULL, NULL, 'ion:settings-outline', b'0', b'0', '${.now?string("yyyy-MM-dd HH:mm:ss")}', '${.now?string("yyyy-MM-dd HH:mm:ss")}');

</#if>
<#assign metaId = metaId + 1>
<#assign menuId = menuId + 1>
<#if customPageConfig.isBatch>
    -- 批量删除按钮
    INSERT INTO `sys_menu_resource` (`id`, `parent_id`, `name`, `menu_name`, `path`, `component`, `description`, `menu_type`, `level`, `permission`, `redirect`, `case_sensitive`, `meta_id`, `is_ext`, `status`, `create_by`, `create_time`, `update_by`, `update_time`) VALUES (${menuId}, ${btnPid}, '${entity}', '${customTableInfo.businessName!table.comment!}-批量删除按钮', '', '', '', 'button', 2, '${package.ModuleName}:${tsModelName}:batch-del:btn', '', b'0', ${metaId}, '0', '0', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}', 'admin', '${.now?string("yyyy-MM-dd HH:mm:ss")}');
    INSERT INTO `sys_menu_meta` (`id`, `title`, `ignore_route`, `order_no`, `hide_menu`, `hide_tab`, `current_active_menu`, `hide_children_in_menu`, `carry_param`, `hide_breadcrumb`, `transition_name`, `frame_src`, `icon`, `affix`, `ignore_keep_alive`, `create_time`, `update_time`) VALUES (${metaId}, '${customTableInfo.businessName!table.comment!}-批量删除按钮', b'0', 2, b'0', b'0', NULL, b'0', b'0', b'0', NULL, NULL, 'ion:settings-outline', b'0', b'0', '${.now?string("yyyy-MM-dd HH:mm:ss")}', '${.now?string("yyyy-MM-dd HH:mm:ss")}');

</#if>

-- =================================================================END----按钮相关sql========================================================================


-- =================================================================BEGIN----接口相关sql========================================================================
    -- 接口权限
    INSERT INTO `sys_permission` ( `id`, `category_id`, `name`, `path`, `type`, `remark`, `status`, `sort`, `create_time`, `update_time`) VALUES (${permissionId}, 2, '${customTableInfo.businessName!table.comment!}', '<#if customConfig.customControllerStrategyConfig.apiPrefix??>${ customConfig.customControllerStrategyConfig.apiPrefix}</#if><#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>/**', 'dashboard', '${customTableInfo.businessName!table.comment!}', b'0', 2, '${.now?string("yyyy-MM-dd HH:mm:ss")}', '${.now?string("yyyy-MM-dd HH:mm:ss")}');
    INSERT INTO `sys_role_permission` (`role_id`, `permission_id`, `create_time`, `update_time`) VALUES ( ${defaultBindRole}, ${permissionId}, '2023-01-17 15:48:36', '2023-01-17 15:48:36');
-- =================================================================END----接口相关sql========================================================================
